package TestDemo;

import java.util.Scanner;

public class Problem2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            if (s.length() < 8) {
                System.out.println("密码太短了");
                continue;
            }

            int flagA = 0, flagNum = 0, flagX = 0, flag = 0;
            String X = "@#$";

            for (int j = 0; j < s.length(); j++) {
                char ch = s.charAt(j);
                if (ch >= '0' && ch <= '9') flagNum = 1;
                else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) flagA = 1;
                else if (X.contains(ch + "")) flagX = 1;
                else flag = 1;
            }

            if (flagA + flagNum + flagX >= 2) System.out.println("密码合法");
            else if (flag > 0) System.out.println("密码中存在非法字符");
            else if (flagA + flagNum + flagX == 1) System.out.println("密码过于简单");
        }
    }
}

